package com.itheima.web.controller.pms;

import com.itheima.common.core.model.AjaxResult;
import com.itheima.pojo.pms.SkuStock;
import com.itheima.service.pms.SkuStockService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sku")
@Slf4j
public class SkuStockController {

    @DubboReference
    private SkuStockService skuStockService;

    /**
     * 批量更新sku库存信息
     * @param skuStockList
     * @param pid
     * @return
     */
    @PostMapping("update/{pid}")
    public AjaxResult update(@RequestBody List<SkuStock> skuStockList, @PathVariable("pid") Long pid){
        log.info("更新sku库存信息：{}",skuStockList);
        skuStockService.adminUpdate(skuStockList,pid);
        return AjaxResult.success("操作成功",null);
    }

    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     * @return
     */
    @GetMapping("{pid}")
    public  AjaxResult selectById(@PathVariable("pid") Long pid,String keyword){
        log.info("查询的信息为：{}，{}",pid,keyword);
        List<SkuStock> skuStockList=skuStockService.selectById(pid,keyword);
        return AjaxResult.success("操作成功",skuStockList);
    }
}
